﻿function AjaxHandler(url, eventAttach)
{
    var self = this;
    this._req = null;
    this._url = url;
    this._eventAttach = eventAttach;
    
    function processReqChanges()
    {
        if (self._req.readyState == 4) {
            if (self._req.status == 200) {
               self._eventAttach(self._req.responseText);
             } else {
                alert("Hubo un problema al procesar el pedido:\n" +
                    self._req.statusText);
             }
        }
    }

    this.SendRequest = function()
    {
        if (window.XMLHttpRequest) {
            this._req = new XMLHttpRequest();
            this._req.onreadystatechange = processReqChanges; //this._process;
            this._req.open("GET", this._url, true);
            this._req.send(null);
        } else if (window.ActiveXObject) {
            this._req = new ActiveXObject("Microsoft.XMLHTTP");
            if (this._req) {
                this._req.onreadystatechange = processReqChanges; //this._process;
                this._req.open("GET", this._url, true);
                this._req.send();
            }
        }
    }
}

function RetrieveResponse(_value)
{
    if (_value == "ok")
        document.getElementById("newCredentials").style.display = "";
    var _loginPanel = document.getElementById("_loginPanel");
    var _loadingPanel = document.getElementById("_LoadingPanel");
    var _recoverPanel = document.getElementById("_recoverPanel");
    _loadingPanel.style.display = "none";
    _recoverPanel.style.display = "none";
    _loginPanel.style.display = "";
}

function RecoverPassword(_email)
{
    var _ajaxHandler = new AjaxHandler("getPassword.aspx?email=" + _email, RetrieveResponse);
    _ajaxHandler.SendRequest();
    var _loadingPanel = document.getElementById("_LoadingPanel");
    _loadingPanel.style.display = "";
    return false;
}

function ShowRecoverPanel()
    {
        var _loginPanel = document.getElementById("_loginPanel");
        var _recoverPanel = document.getElementById("_recoverPanel");
        _loginPanel.style.display = "none";
        _recoverPanel.style.display = "";
        document.getElementById("newCredentials").style.display = "none";
    }
    
function ShowLoginPanel()
    {
        var _loginPanel = document.getElementById("_loginPanel");
        var _recoverPanel = document.getElementById("_recoverPanel");
        _loginPanel.style.display = "";
        _recoverPanel.style.display = "none";
    }
    
    
function SwitchCode(elementId)
    {
        var e = document.getElementById(elementId);
        var img = e.previousSibling.firstChild.firstChild;
        if ( e.style.display != 'none' ) {
            e.style.display = 'none';
		    img.setAttribute('src','/images/plus.gif');
		    img.setAttribute('style', 'border-width:0px;vertical-align:middle;');
		}
        else
        {
            e.style.display = '';
		    img.setAttribute('src','/images/minus.gif');
		    img.setAttribute('style', 'border-width:0px;vertical-align:middle;');
        }
    }    